package com.matrix.rabbitmqtest.workqueues;

import com.matrix.rabbitmqtest.util.AppKeys;
import com.matrix.rabbitmqtest.util.RabbitMQUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;

import java.nio.charset.StandardCharsets;
import java.util.Map;

/**
 * 生产者
 */
public class Producer {
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtil.getChannel();
        channel.queueDeclare(AppKeys.QUEUE_NAME, false, false, true, (Map) null);
        int count = 1;
        // 发送103条数据到MQ中
        while (count<=103){
            channel.basicPublish("", AppKeys.QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN,("你好世界"+count).getBytes(StandardCharsets.UTF_8));
            System.out.println("发送完毕"+count);
            count++;
//            Thread.sleep(1000);
        }
    }
}
